package com.design.patterns.list.factory.simplefactory;

import com.design.patterns.list.factory.Pizza;

/**
 * 简单工厂模式：
 * 1.传入工厂的方法：
 *      A: 直接工厂的静态方法
 *      B: 传入工厂对象，使用工厂对象创建pizza对象
 *      C: 在实现类里直接定义工厂对象
 * @author Wangzhiwen
 */
public class OrderPizza {

    public static void print(String pizzaName){
        Pizza pizza = SimpleFactory.createPizzaStatic(pizzaName);
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
    }

    private SimpleFactory simpleFactory;

    public OrderPizza() {
    }

    /**
     * 构造器传入pizza工厂
     */
    public OrderPizza(SimpleFactory factory) {
        this.simpleFactory = factory;
    }

    /**
     * 通过set方法传入pizza工厂
     */
    public void setSimpleFactory(SimpleFactory factory){
        this.simpleFactory = factory;
    }

    public void pizza(String pizzaName){
        Pizza pizza = simpleFactory.createPizza(pizzaName);
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
    }

}
